<template>
  <div class="d_main">
    <na-table
      :datas.sync="tableData"
      :searchObj.sync="search"
      @updateDatas="getAllMaterils"
      @newAdd="newAddClick"
      @checkboxChange="handleCheckboxChange"
    >
      <template #slot1>
        <el-button size="small" type="primary" @click="handleImport"
          ><i class="el-icon-upload el-icon--left" style="font-size: 12px"></i
          >导入</el-button
        >
      </template>
    </na-table>
    <fileImport :per-visible.sync="showImport" @upData="importUpData" />
    <el-dialog
      :title="tname"
      :visible.sync="isAddProduct"
      :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog"
      width="85%"
      @close="closeDialog"
      destroy-on-close
    >
      <div class="dialogDody">
        <div class="addWuliaoBox">
          <el-form
            ref="ProductForm"
            :model="ProductForm"
            :rules="rules"
            label-width="110px"
            class="dialogForm dialogInlineForm"
            :disabled="canDiable"
          >
            <div>
              <div class="cTitle">
                <h3>申请信息</h3>
              </div>
              <el-row :gutter="10">
                <el-col :span="8">
                  <el-form-item label="刀版编号">
                    <el-input
                      v-model="ProductForm.knifeVersionNo"
                      placeholder="系统自动生成"
                      disabled
                      size="small"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="创建日期" prop="createTime">
                    <el-input
                      v-model="ProductForm.createTime"
                      placeholder="请填写创建日期"
                      disabled
                      size="small"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="创建人员" prop="creatorName">
                    <el-input
                      v-model="ProductForm.creatorName"
                      placeholder="请填写创建人员"
                      size="small"
                      disabled
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="刀版名称" prop="knifeVersionName">
                    <el-input
                      v-model="ProductForm.knifeVersionName"
                      placeholder="请输入刀版名称"
                      size="small"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="存放位置" prop="storageLocation">
                    <el-input
                      v-model="ProductForm.storageLocation"
                      placeholder="请输入存放位置"
                      size="small"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="刀版号" prop="knifeVersionNumber">
                    <el-input
                      v-model="ProductForm.knifeVersionNumber"
                      placeholder="请输入刀版号"
                      size="small"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :span="8">
                  <el-form-item label="刀版尺寸">
                    <el-input
                      v-model="ProductForm.knifeVersionSize"
                      placeholder="请输入刀版尺寸"
                      size="small"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="刀版类型" prop="knifeVersionType">
                    <el-select
                        filterable
                      v-model="ProductForm.knifeVersionType"
                      placeholder="请选择"
                      size="small"
                      @change="handleTypeChange"
                    >
                      <el-option label="公用" :value="1"> </el-option>
                      <el-option label="私用" :value="0"> </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="所属客户" prop="customerCode">
                    <el-select
                        filterable
                      v-model="ProductForm.customerCode"
                      size="small"
                      :disabled="isDisableUser"
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="item in userList"
                        :key="item.customerCode"
                        :label="item.customerName"
                        :value="item.customerCode"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :span="8">
                  <el-form-item label="模数">
                    <el-input
                      v-model="ProductForm.modulus"
                      placeholder="请输入模数"
                      size="small"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="跳距" prop="jumpDistance">
                    <el-input
                      v-model="ProductForm.jumpDistance"
                      placeholder="请输入跳距"
                      size="small"
                    >
                      <template slot="append">mm</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="已使用刀次" prop="usedKnifeTimes">
                    <el-input
                      v-model="ProductForm.usedKnifeTimes"
                      placeholder="请输入已使用刀次"
                      size="small"
                    >
                      <template slot="append">次</template>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :span="8">
                  <el-form-item label="预警刀次" prop="warningKnifeTimes">
                    <el-input
                      v-model="ProductForm.warningKnifeTimes"
                      placeholder="请输入预警刀次"
                      size="small"
                    >
                      <template slot="append">次</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="使用日期" prop="useDate">
                    <el-date-picker
                      v-model="ProductForm.useDate"
                      type="date"
                      size="small"
                      placeholder="选择日期"
                      value-format="yyyy-MM-dd"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="使用期" prop="serviceLife">
                    <el-input
                      v-model="ProductForm.serviceLife"
                      placeholder="请输入模数"
                      size="small"
                    >
                      <template slot="append">月</template>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row style="margin-top: 5px">
                <el-col :span="24">
                  <el-form-item label="备注" class="knifeVersionRemark">
                    <el-input
                      v-model="ProductForm.knifeVersionRemark"
                      type="textarea"
                      :rows="3"
                      placeholder="请填写备注"
                      size="small"
                      clearable
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
            <div class="cTitle">
              <h3>刀版明细</h3>
            </div>
            <el-table :data="ProductForm.detailList" border style="width: 100%">
              <el-table-column type="index" label="序号" width="50" />
              <el-table-column
                prop="width"
                align="center"
                label="宽"
                width="100"
              >
                <template slot-scope="scope">
                  <el-input
                    v-model.number="scope.row.width"
                    placeholder="请输入"
                    size="small"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="height"
                align="center"
                label="高"
                width="100"
              >
                <template slot-scope="scope">
                  <el-input
                    v-model.number="scope.row.height"
                    placeholder="请输入"
                    size="small"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="spacing"
                align="center"
                label="间距"
                width="100"
              >
                <template slot-scope="scope">
                  <el-input
                    v-model.number="scope.row.spacing"
                    placeholder="请输入"
                    size="small"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="shape"
                align="center"
                label="形状"
                width="150"
              >
                <template slot-scope="scope">
                  <el-select
                    v-model="scope.row.shape"
                    placeholder="请选择"
                    size="small"
                    filterable
                    @change="
                      handleSelectChange(scope.row, scope.$index, $event)
                    "
                  >
                    <el-option
                      v-for="item in tagShapeList"
                      :key="item.objectValue"
                      :label="item.objectName"
                      :value="item.objectValue"
                    />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column
                prop="rAngle"
                align="center"
                label="R角"
                width="100"
              >
                <template slot-scope="scope">
                  <el-input
                    v-model.number="scope.row.rAngle"
                    placeholder="请输入"
                    size="small"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="direction"
                align="center"
                label="方向"
                width="110"
              >
                <template slot-scope="scope">
                  <el-select
                    v-model="scope.row.direction"
                    placeholder="请选择"
                    size="small"
                    filterable
                    @change="
                      handleSelectChange(scope.row, scope.$index, $event)
                    "
                  >
                    <el-option label="宽" :value="0"> </el-option>
                    <el-option label="高" :value="1"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column
                prop="quantity"
                align="center"
                label="数量"
                width="100"
              >
                <template slot-scope="scope">
                  <el-input
                    v-model.number="scope.row.quantity"
                    placeholder="请输入"
                    size="small"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="remark" align="center" label="备注">
                <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.remark"
                    placeholder="请输入"
                    size="small"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                width="100px"
                fixed="right"
                align="center"
                v-if="this.opsid != 2"
              >
                <template slot-scope="scope">
                  <div class="flex flex_between pl12 pr12">
                    <i
                      class="el-icon-document-copy"
                      v-if="scope.$index != ProductForm.detailList.length - 1"
                      @click="handleCopyRow(scope.row, scope.$index)"
                    ></i>
                    <i
                      class="el-icon-delete"
                      v-if="scope.$index != ProductForm.detailList.length - 1"
                      @click="handleDeleteRow(scope.row, scope.$index)"
                    ></i>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div class="cTitle">
              <h3>刀版图片</h3>
            </div>
            <el-upload
              action="#"
              list-type="picture-card"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove"
              :http-request="myUpload"
              :disabled="canDiable"
              :file-list="ProductForm.fileList"
              :class="{ hideUpload: canDiable }"
            >
              <i class="el-icon-plus"></i>
            </el-upload>
            <el-image-viewer
              v-if="dialogVisible"
              :url-list="dialogImageUrl"
              :on-close="closeViewer"
              :initial-index="viewImgIndex"
              :on-switch="onSwitch"
              :z-index="3000"
            />
          </el-form>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isAddProduct = false">取 消</el-button>
        <!-- 新增       -->
        <el-button
          v-if="opsid !== 2"
          :loading="addProductLoading"
          :disabled="addProductLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="savell"
          >{{ btm }}</el-button
        >
      </div>
    </el-dialog>

    <!-- 原因   -->
    <el-dialog
      :title="typeLabel + '原因'"
      :visible.sync="isNopassshow"
      :close-on-click-modal="false"
      custom-class="comDialog"
      width="40%"
    >
      <div class="dialogDody">
        <el-form
          ref="passForm"
          :model="voidForm"
          class="dialogForm"
          :rules="passFormRules"
        >
          <el-form-item class="mt12" prop="reason">
            <el-input
              v-model="voidForm.reason"
              type="textarea"
              placeholder="请输入内容"
              :autosize="{ minRows: 6 }"
              size="mini"
            />
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isNopassshow = false">取 消</el-button>
        <el-button
          :disabled="addLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="passSave"
          >提交</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { arraySort, formatDate } from "@/utils";
import HeadSeting from "@/components/HeadSeting";
import Pagination from "@/components/Pagination";
import perRedioDialog from "@/components/perDialogRedio";
import selectProductOrder from "@/components/selectProductOrder";
import screec from "@/components/screen";
import { mapGetters } from "vuex";
import naTable from "@/components/naTable";
import fileImport from "@/components/fileImport";

export default {
  name: "editionAdmin",
  components: {
    Pagination,
    HeadSeting,
    perRedioDialog,
    selectProductOrder,
    screec,
    naTable,
    fileImport,
    "el-image-viewer": () =>
      import("element-ui/packages/image/src/image-viewer"),
  },
  data() {
    return {
      ops: "add", // 操作、新建，修改，查看
      opsid: 1, // 3 确定 1 新建， 4 修改， 2 查看
      searchLoading: false, // 搜索加载效果
      allMaterirls: [], // 全部数据列表
      addLoading: false,
      isNopassshow: false,
      imgList: [], //上传图片列表
      userList: [], //使用客户下拉数据
      tagShapeList: [], //标签形状下拉数据
      showImport: false, //导入组件显示状态
      isDisableUser: false,
      viewImgIndex: 0, //预览图片下标
      typeLabel: "",
      passFormRules: {
        reason: [{ required: true, message: "请输入原因", trigger: "blur" }],
      },

      tableData: {
        headId: "head", //表头列显隐组件所需ID-避免多个页面id重复问题
        tableId: "dataBillID", //表格列表key,也就是一条数据的唯一标识
        senior: false, //高级搜索是否显示
        addPermission: "", //新建按钮权限
        disableWord: "isDisable", //是否禁用显示的字段
        disableStatus: "启用", //判断未禁用的状态值
        //表格按钮
        operationBtn: [
          {
            title: "查看",
            methodsName: "handleClick",
          },
          {
            title: "修改",
            methodsName: "handleUpdata",
            permission: "",
            hideCondition: {
              //按钮显隐条件
              prop: "knifeVersionState", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用-值必须跟状态的类型保持一致
                '正常',
              ],
            },
          },
          {
            title: "作废",
            methodsName: "handleDone",
            permission: "",
            isShowCheckbox: true,
            hideCondition: {
              //按钮显隐条件
              prop: "knifeVersionState", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用-值必须跟状态的类型保持一致
                '正常'
              ],
            },
          },
          {
            title: "报废",
            methodsName: "handleScrap",
            permission: "",
            hideCondition: {
              //按钮显隐条件
              prop: "knifeVersionState", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用-值必须跟状态的类型保持一致
                '正常'
              ],
            },
          },
          {
            title: "复制",
            methodsName: "handleCopy",
            permission: "",
          },
          {
            title: "禁用",
            methodsName: "setMateriel",
            hideCondition: {
              //按钮显隐条件
              prop: "knifeVersionState", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用-值必须跟状态的类型保持一致
                '正常',
              ],
            },
          },
          {
            title: "删除",
            methodsName: "handleDelete",
            permission: "",
            hideCondition: {
              //按钮显隐条件
              prop: "knifeVersionState", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用-值必须跟状态的类型保持一致
                '正常','已作废'
              ],
            },
          },
        ],
        //表格内容
        tbody: [],
        //表格表头
        thead: [],
      },

      voidForm: {
        type: 0, //状态类型：0刀版状态；1启用状态
        knifeVersionNo: "", //刀版编号
        reason: "", //原因
        state: 0, //Type为0时：0正常；1作废；2报废，Type为1时：0启用，1禁用
      },
      // 表单操作
      ProductForm: {
        knifeVersionState: 0, //刀版状态：0制作中；1已完成；2已作废
        knifeVersionSize: "", //刀版尺寸
        knifeVersionType: "", //刀版类型：0私用，1公用
        isCopy: false,
        customerCode: "", //客户编号
        modulus: "", //刀版模数
        knifeVersionName:"",
        storageLocation:"",
        knifeVersionNumber:"",
        jumpDistance: "", //	跳距
        usedKnifeTimes: "", //已使用刀次
        warningKnifeTimes: "", //预警刀次
        useDate: "", //使用日期dayjs().format('YYYY-MM-DD')
        serviceLife: "", //使用期限（月）
        knifeVersionRemark: "", //刀版备注
        createBy: "", //创建人员
        detailList: [
          {
            knifeDetailNo: "", //刀版明细编号
            knifeVersionNo: "", //刀版编号
            width: "", //宽
            spacing: "", //间距
            height: "", //高
            shape: "", //形状
            rAngle: "", //R角
            direction: "", //方向
            quantity: "", //数量
            remark: "", //备注
          },
        ],
        fileList: [],
        addFileList: [],
        deleteFileList: [],
      },
      formObj: {},

      dialogVisible: false,
      dialogImageUrl: [],

      // 搜索条件
      search: {
        queryDataBaseFiled: "",
        pageIndex: 1,
        pageSize: 30,
        likeWords: "",
        isShowDisabled: 0, //	是否显示禁用,0显示，1不显示
        knifeVersionState: -1, //刀版状态：0制作中；1已完成；2已作废，-1查询全部
        total: 0,
      },
      addProductLoading: false,
      isAddProduct: false,
      rowData: "",
      isperShow: false,
      canDiable: false,
      rules: {
        knifeVersionName: [
          { required: true, message: "请输入刀版名称", trigger: "blur" },
        ],
        knifeVersionType: [
          { required: true, message: "请选择刀版类型", trigger: "change" },
        ],
      },
    };
  },
  computed: {
    ...mapGetters(["name", "userInfo"]),
    btm() {
      if (this.opsid === 3) {
        return "确认";
      } else {
        return "保存";
      }
    },
    tname() {
      if (this.opsid === 1) {
        return "新建刀版";
      } else if (this.opsid === 2) {
        return "查看刀版";
      } else if (this.opsid === 4) {
        return "修改刀版";
      } else if (this.opsid === 5) {
        return "复制刀版";
      }
    },
  },
  created() {
    //  所有列表数据
    this.getAllMaterils();
    // 表格得表头
    this.getTableHead();
    //获取使用用户数据
    this.getUserList();

    //获取标签形状
    this.getShapeList();
    this.formObj = JSON.parse(JSON.stringify(this.ProductForm));
  },
  mounted() {},
  updated() {},
  methods: {
    //导入
    handleImport() {
      this.showImport = true;
    },

    //明细下拉框选择事件
    handleSelectChange(row, index, event) {
      if (index == this.ProductForm.detailList.length - 1) {
        this.ProductForm.detailList.push({
          knifeDetailNo: "", //刀版明细编号
          knifeVersionNo: "", //刀版编号
          width: "", //宽
          spacing: "", //间距
          height: "", //高
          shape: "", //形状
          rAngle: "", //R角
          direction: "", //方向
          quantity: "", //数量
          remark: "", //备注
        });
      }
    },

    //查看图片
    handlePictureCardPreview(file) {
      this.viewImgIndex = this.ProductForm.fileList.findIndex((item) => {
        return item.url == file.url;
      });
      this.dialogVisible = true;
    },

    //图片预览关闭事件
    closeViewer() {
      this.dialogVisible = false;
    },

    onSwitch(e) {
      console.log(e);
    },

    //获取使用用户数据
    getUserList() {
      this.$api.system.GetAllCanUseCustomers().then((res) => {
        this.userList = res;
      });
    },

    //显示作废选择事件
    handleCheckboxChange(e) {
      if (e) {
        this.search.isShowDisabled = 1;
      } else {
        this.search.isShowDisabled = 0;
      }
      this.search.pageIndex = 1;
      this.getAllMaterils();
    },

    //刀版类型下拉选择事件
    handleTypeChange(e) {
      if (e == 0) {
        this.isDisableUser = false;
      } else {
        this.isDisableUser = true;
        this.ProductForm.customerCode = "";
      }
    },

    //删除文件
    handleRemove(file, fileList) {
      this.ProductForm.fileList = fileList;
      this.dialogImageUrl = this.ProductForm.fileList.map((x) => {
        return x.url;
      });
      if (file.knifeVersionFileNo) {
        this.ProductForm.deleteFileList.push(file);
      }
      this.ProductForm.addFileList = [];
      fileList.forEach((item) => {
        if (!item.knifeVersionFileNo) {
          this.ProductForm.addFileList.push(item);
        }
      });
    },

    //设置状态 禁用/启用
    setMateriel(row) {
      let state;
      if (row.isDisable == "启用") {
        state = 1;
      } else {
        state = 0;
      }
      let obj = {
        type: 1, //状态类型：0刀版状态；1启用状态
        knifeVersionNo: row.knifeVersionNo, //刀版编号
        state: state, //Type为0时：0正常；1作废；2报废，Type为1时：0启用，1禁用
      };
      this.$api.product.UpdateKnifeVersionState(obj).then((res) => {
        this.$message.success("设置成功");
        this.getAllMaterils();
      });
    },

    // 新建点击事件
    newAddClick() {
      this.ops = "add";
      this.ProductForm = JSON.parse(JSON.stringify(this.formObj));
      this.ProductForm.fileList = [];
      // this.$refs['ProductForm'].clearValidate('knifeVersionType');
      this.ProductForm.useDate = this.dayjs().format("YYYY-MM-DD");
      this.ProductForm.createTime = this.dayjs().format("YYYY-MM-DD HH:mm:ss");
      this.ProductForm.creatorName = this.name;
      this.isAddProduct = true;
      this.opsid = 1;
      this.canDiable = false;
    },
    //查看
    handleClick(row) {
      this.opsid = 2;
      this.canDiable = true;
      this.getDetail(row);
    },

    // 上传文件
    myUpload(e) {
      let type = e.file.name.split(".");
      if (type[type.length - 1] != "png" && type[type.length - 1] != "jpg") {
        this.$message.warning("请上传图片文件");
        return;
      }
      const file = e.file;
      var formData = new FormData();
      formData.append("file", file);
      this.$api.common.UploadSingleFile(formData).then((res) => {
        this.ProductForm.fileList.push({
          knifeVersionFileNo: "", //刀版文件编号
          knifeVersionFileName: res.fileName, //文件名称
          url: res.fileFullUrl, //回显图片路径
          knifeVersionFileSize: res.fileSize, //文件大小
          knifeVersionFileUrl: res.fileFullUrl, //文件路径
          knifeVersionFilePreview: res.thumbnailWebSiteUrl, //预览图
          uploadPerson: "", //上传人员
        });
        if (this.opsid == 4) {
          this.ProductForm.addFileList.push({
            knifeVersionFileNo: "", //刀版文件编号
            knifeVersionFileName: res.fileName, //文件名称
            url: res.fileFullUrl, //回显图片路径
            knifeVersionFileSize: res.fileSize, //文件大小
            knifeVersionFileUrl: res.fileFullUrl, //文件路径
            knifeVersionFilePreview: res.thumbnailWebSiteUrl, //预览图
            uploadPerson: "", //上传人员
          });
        }
        this.dialogImageUrl = this.ProductForm.fileList.map((x) => {
          return x.url;
        });
      });
    },

    //复制明细
    handleCopyRow(row, index) {
      this.ProductForm.detailList.splice(
        index,
        0,
        JSON.parse(JSON.stringify(row))
      );
    },

    //删除单条明细
    handleDeleteRow(row, index) {
      this.ProductForm.detailList.splice(index, 1);
    },

    //确定
    handleConfirm(row) {
      this.opsid = 3;
      this.canDiable = true;
      this.rowData = row;
      this.getDetail(row);
    },
    //作废
    handleDone(row) {
      this.rowData = row;
      this.typeLabel = "作废";
      this.voidForm.reason = "";
      this.isNopassshow = true;
    },

    //报废
    handleScrap(row) {
      this.rowData = row;
      this.typeLabel = "报废";
      this.voidForm.reason = "";
      this.isNopassshow = true;
    },

    //复制
    handleCopy(row) {
      this.opsid = 5;
      this.canDiable = false;
      this.getDetail(row);
    },

    //修改
    handleUpdata(row) {
      this.opsid = 4;
      this.canDiable = false;
      this.getDetail(row);
    },

    //作废/报废提交
    passSave() {
      if (this.typeLabel == "作废") {
        this.voidForm.type = 0;
        this.voidForm.knifeVersionNo = this.rowData.knifeVersionNo;
        this.voidForm.state = 1;
      } else {
        this.voidForm.type = 0;
        this.voidForm.knifeVersionNo = this.rowData.knifeVersionNo;
        this.voidForm.state = 2;
      }
      this.$refs.passForm.validate((valid) => {
        if (valid) {
          this.$api.product
            .UpdateKnifeVersionState(this.voidForm)
            .then((res) => {
              this.$message.success(this.typeLabel + "成功");
              this.getAllMaterils();
              this.isNopassshow = false;
            });
        }
      });
    },

    // 得到标签形状数据列表
    getShapeList() {
      this.$api.business.QueryTagShapeDataList().then((res) => {
        res.forEach((item) => {
          item.objectValue = Number(item.objectValue);
        });
        this.tagShapeList = res;
      });
    },

    //删除
    handleDelete(row) {
      const _data = {
        entityID: row.knifeVersionID,
        entityCode: row.knifeVersionNo,
      };
      this.$confirm("确定删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$api.product
          .DeleteKnifeVersion(_data)
          .then(() => {
            this.getAllMaterils();
            this.$message({
              message: "删除成功",
              type: "success",
            });
          })
          .catch(() => {});
      });
    },
    getDetail(row) {
      const _data = {
        queryBy: 1,
        queryValue: row.knifeVersionID,
      };
      this.$api.product.GetSingleKnifeVersionView(_data).then((res) => {
        this.ProductForm = res;
        this.ProductForm.addFileList = [];
        this.ProductForm.deleteFileList = [];
        this.ProductForm.fileList.forEach((item) => {
          item.url = item.knifeVersionFileUrl;
        });
        this.dialogImageUrl = this.ProductForm.fileList.map((x) => {
          return x.url;
        });
        if (this.opsid != 2) {
          this.ProductForm.detailList.push({
            knifeDetailNo: "", //刀版明细编号
            knifeVersionNo: "", //刀版编号
            width: "", //宽
            spacing: "", //间距
            height: "", //高
            shape: "", //形状
            rAngle: "", //R角
            direction: "", //方向
            quantity: "", //数量
            remark: "", //备注
          });
        }
        if (res.knifeVersionType == 0) {
          this.isDisableUser = false;
        } else {
          this.isDisableUser = true;
        }
        this.isAddProduct = true;
      });
    },
    savell() {
      if (this.ProductForm.detailList.length == 1) {
        this.$message.warning("请选择明细");
        return;
      }

      this.ProductForm.detailList.forEach((item, index) => {
        if (!item.shape) {
          this.ProductForm.detailList.splice(index, 1);
        }
      });
      if (this.opsid === 1 || this.opsid === 5) {
        if (this.opsid === 5) {
          this.ProductForm.knifeVersionID = 0;
          this.ProductForm.knifeVersionNo = "";
          this.ProductForm.isCopy = true;
        }
        //新建
        this.$refs.ProductForm.validate((valid) => {
          if (valid) {
            this.addProductLoading = true;
            this.$api.product
              .CreateKnifeVersion(this.ProductForm)
              .then(() => {
                this.addProductLoading = false;
                this.isAddProduct = false;
                this.getAllMaterils();
                this.$message({
                  message: "保存成功",
                  type: "success",
                });
              })
              .catch(() => {
                this.addProductLoading = false;
                this.ProductForm.detailList.push({
                  knifeDetailNo: "", //刀版明细编号
                  knifeVersionNo: "", //刀版编号
                  width: "", //宽
                  spacing: "", //间距
                  height: "", //高
                  shape: "", //形状
                  rAngle: "", //R角
                  direction: "", //方向
                  quantity: "", //数量
                  remark: "", //备注
                });
              });
          }
        });
      } else if (this.opsid === 4) {
        //修改
        this.$refs.ProductForm.validate((valid) => {
          if (valid) {
            this.addProductLoading = true;
            this.$api.product
              .UpdateKnifeVersion(this.ProductForm)
              .then(() => {
                this.addProductLoading = false;
                this.isAddProduct = false;
                this.getAllMaterils();
                this.$message({
                  message: "修改成功",
                  type: "success",
                });
              })
              .catch(() => {
                this.addProductLoading = false;
                this.ProductForm.detailList.push({
                  knifeDetailNo: "", //刀版明细编号
                  knifeVersionNo: "", //刀版编号
                  width: "", //宽
                  spacing: "", //间距
                  height: "", //高
                  shape: "", //形状
                  rAngle: "", //R角
                  direction: "", //方向
                  quantity: "", //数量
                  remark: "", //备注
                });
              });
          }
        });
      }
    },

    importUpData() {
      this.search.pageIndex = 1;
      this.getAllMaterils();
    },

    // 获取表格表头
    getTableHead() {
      const parmas = {
        tableCode: this.$config.KnifeVersionTable,
      };
      this.$api.common.getAllTableHead(parmas).then((res) => {
        res.sort(arraySort("columnSort"));
        this.tableData.thead = res;
      });
    },
    // 所有列表数据
    getAllMaterils() {
      const parmas = this.search;
      this.searchLoading = true;
      this.$api.product
        .GetPageKnifeVersionList(parmas)
        .then((res) => {
          res.list.forEach((item) => {
            if (item.isDisable == 0) {
              item.isDisable = "启用";
            } else {
              item.isDisable = "禁用";
            }
            if (item.knifeVersionState == 0) {
              item.knifeVersionState = "正常";
            } else if (item.knifeVersionState == 1) {
              item.knifeVersionState = "已作废";
            } else {
              item.knifeVersionState = "已报废";
            }
            if (item.knifeVersionType == 0) {
              item.knifeVersionType = "私用";
            } else {
              item.knifeVersionType = "公用";
            }
          });
          this.allMaterirls = res.list;
          this.allMaterirls.forEach((item) => {
            for (let i in item) {
              if (!item[i] && item[i] !== 0) {
                item[i] = "--";
              }
            }
          });
          this.tableData.tbody = res.list;
          this.search.total = res.totalCount;
          this.searchLoading = false;
        })
        .catch(() => {
          this.searchLoading = false;
        });
    },
    // 新建弹框关闭事件
    closeDialog() {},
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-form-item__label::before {
  left: 20px;
}
.container {
  height: 100%;
}
.permangeRg {
  border: 1px solid #e6e6e6;
  background: #fff;
  height: 100%;

  .mainTT {
    font-size: 16px;
    font-weight: bold;
    width: 100%;
    padding: 18px 16px;
    padding-bottom: 0;
  }
}
.addWuliaoBox {
  padding: 10px 16px;

  .tableBox {
    margin-top: 16px;
    border: 1px solid #e6e6e6;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    overflow: hidden;

    .tt {
      height: 38px;
      line-height: 38px;
      padding-left: 16px;
      background: #f7f8fa;
      border-radius: 8px 8px 0 0;
    }
  }
}
::v-deep .el-form-item__label {
  padding-bottom: 0 !important;
  padding-left: 8px;
}

::v-deep .el-form-item {
  margin-bottom: 5px;
}
.subTip {
  border-bottom: 1px #e6e6e6 solid;
  background: #f5f6f9;
  padding: 8px 16px;
}

::v-deep .hideUpload {
  .el-upload.el-upload--picture-card {
    display: none;
  }
}

::v-deep .el-upload-list__item {
  transition: none !important;
}
</style>
